/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nightonke.boommenusample.slice;

import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenusample.BuilderManager;
import com.nightonke.boommenusample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.AbsButton;
import ohos.agp.components.Slider;
import ohos.agp.components.Switch;
import ohos.agp.components.Text;

public class ThreeDAnimationAbilitySlice extends AbilitySlice {

    private Text durationTextView;
    private BoomMenuButton bmb1;
    private BoomMenuButton bmb2;
    private BoomMenuButton bmb3;

    /**
     * onStart
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_three_danimation);

        bmb1 = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb1);
        for (int i = 0; i < bmb1.getPiecePlaceEnum().pieceNumber(); i++)
            bmb1.addBuilder(BuilderManager.getSquareSimpleCircleButtonBuilder());

        bmb2 = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb2);
        for (int i = 0; i < bmb2.getPiecePlaceEnum().pieceNumber(); i++)
            bmb2.addBuilder(BuilderManager.getHamButtonBuilderWithDifferentPieceColor());

        bmb3 = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb3);
        for (int i = 0; i < bmb3.getPiecePlaceEnum().pieceNumber(); i++)
            bmb3.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder());

        Switch threeDAnimationSwitch = (Switch) findComponentById(ResourceTable.Id_three_d_animation_switch);
        threeDAnimationSwitch.setStateOffText("OFF");
        threeDAnimationSwitch.setStateOnText("ON");
        threeDAnimationSwitch.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
            @Override
            public void onCheckedChanged(AbsButton absButton, boolean isChecked) {
                bmb1.setUse3DTransformAnimation(isChecked);
                bmb2.setUse3DTransformAnimation(isChecked);
                bmb3.setUse3DTransformAnimation(isChecked);
            }
        });
        threeDAnimationSwitch.setChecked(true);

        Slider durationSeekBar = (Slider) findComponentById(ResourceTable.Id_duration_seek);
        durationSeekBar.setMaxValue(3000);
        durationSeekBar.setProgressValue(300);
        durationSeekBar.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int progress, boolean b) {
                durationTextView.setText("Show/Hide duration = " + slider.getProgress() + " ms");
                bmb1.setDuration(progress);
                bmb2.setDuration(progress);
                bmb3.setDuration(progress);
            }

            @Override
            public void onTouchStart(Slider slider) {

            }

            @Override
            public void onTouchEnd(Slider slider) {

            }
        });

        durationTextView = (Text) findComponentById(ResourceTable.Id_duration_text);
        durationTextView.setText("Show/Hide duration = " + durationSeekBar.getProgress() + " ms");
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     * @param intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
